package la.iok.hzsvn.lewin.movie.cloud.controller;

import la.iok.hzsvn.lewin.movie.cloud.service.DeviceService;
import la.iok.hzsvn.lewin.movie.core.model.DeviceVo;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("internal-api/devices")
public class DeviceInternalController {
    private final DeviceService deviceService;

    public DeviceInternalController(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    @GetMapping("{id}")
    public SingleDataResponse<DeviceVo> deviceInfo(@PathVariable Long id){
        return new SingleDataResponse<>(deviceService.po2vo(deviceService.select(id)));
    }

    @GetMapping("code/{deviceCode}")
    public SingleDataResponse<DeviceVo> deviceInfo(@PathVariable String deviceCode){
        return new SingleDataResponse<>(deviceService.po2vo(deviceService.select(deviceCode)));
    }
}
